home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Pascal
/
SWar
/
Init.p
< prev
next >
Wrap
Text File
|
1995-06-15
|
5KB
|
212 lines
unit Init;
interface
uses
{$IFC UNDEFINED THINK_PASCAL}
Types, QuickDraw, Events, Menus, Dialogs, Fonts, Resources, Devices,
ToolUtils,
{$ENDC}
Globals, Util;
procedure ToolBoxInit;
procedure WindowInit;
procedure LoadPieces;
procedure InitColors;
implementation
procedure InitColors;
begin
myGreen.red := 0;
myGreen.green := -1;
myGreen.blue := 0;
myYellow.red := -1;
myYellow.green := -1;
myYellow.blue := 0;
myRed.red := -1;
myRed.green := 0;
myRed.blue := 0;
myBlue.red := 25000;
myBlue.green := 55000;
myBlue.blue := -1;
myDkBlue.red := 10000;
myDkBlue.green := 10000;
myDkBlue.blue := -1;
myWhite.red := -1;
myWhite.green := -1;
myWhite.blue := -1;
myBlack.red := 0;
myBlack.green := 0;
myBlack.blue := 0;
myGray.red := 20000;
myGray.green := 20000;
myGray.blue := 20000;
myOrange.red := 40000;
myOrange.green := 25000;
myOrange.blue := 8000;
end;
{$IFC DEFINED THINK_PASCAL}
FUNCTION GetMenuHandle(menuID: INTEGER): MenuRef;
INLINE $A949;
PROCEDURE AppendResMenu(theMenu: MenuRef; theType: ResType);
INLINE $A94D;
{$ENDC}
procedure MenuBarInit;
var
myMenuBar: Handle;
begin
myMenuBar := GetNewMBar(500);
SetMenuBar(myMenuBar);
gFileMenu := GetMenuHandle(501);
gEditMenu := GetMenuHandle(502);
gAppleMenu := GetMenuHandle(500);
if (gAppleMenu <> nil) then
AppendResMenu(gAppleMenu, 'DRVR');
end; (* MenuBarInit() *)
function PortInit (myRect: Rect; depth: Integer; portName: Str255): CGrafPtr;
var
bytes: LongInt;
myBits: Ptr;
savePort: GrafPtr;
newGrafPtr: GrafPtr;
newCGrafPtr: CGrafPtr;
begin
GetPort(savePort);
newCGrafPtr := CGrafPtr(NewPtr(sizeof(CGrafPort)));
if newCGrafPtr = nil then
begin
ExitAppl;
end; (* if *)
if gColorQDFlag then
OpenCPort(newCGrafPtr)
else
OpenPort(GrafPtr(newCGrafPtr));
bytes := BSL(BSR(depth * (myRect.right - myRect.left) + 15, 4), 1);
myBits := NewPtr(bytes * (myRect.bottom - myRect.top));
if (depth = 1) then
begin
newGrafPtr := GrafPtr(newCGrafPtr);
newGrafPtr^.portBits.baseAddr := myBits;
newGrafPtr^.portBits.rowBytes := bytes;
newGrafPtr^.portBits.bounds := myRect;
end (* if *)
else
begin
newCGrafPtr^.portPixMap^^.baseAddr := myBits;
newCGrafPtr^.portPixMap^^.rowBytes := BitOr(bytes, $8000);
newCGrafPtr^.portPixMap^^.bounds := myRect;
newCGrafPtr^.portPixMap^^.hRes := 72;
newCGrafPtr^.portPixMap^^.vRes := 72;
newCGrafPtr^.portRect := myRect;
end; (* else *)
{ Must set FG and BG pens for black background}
{ }
if depth > 1 then
begin
RGBForeColor(myBlack);
RGBBackColor(myBlack);
end;
{ Erase entire port}
{ }
EraseRect(myRect);
{ restore old port value (game screen)}
{}
SetPort(savePort);
PortInit := newCGrafPtr;
end; (* PortInit() *)
procedure WindowInit;
var
myRect: Rect;
depth: Integer;
savePort: GrafPtr;
{ e CWindowPtr gPictureWindow:xtern;}
{ e CGrafPort *gOSPtr, *gScrapPtr:xtern;}
begin
GetPort(savePort);
gPictureWindow := CWindowPtr(GetNewCWindow(500, nil, WindowPtr(-1)));
SetPort(GrafPtr(gPictureWindow));
{ Must set FG and BG pens for CopyBits to work}
{ }
RGBForeColor(myBlack);
RGBBackColor(myWhite);
{ Create offscreen port for game playing field}
{}
myRect := gPictureWindow^.portRect;
depth := gPictureWindow^.portPixMap^^.pixelSize;
gOldDepth := depth;
gOSPtr := CGrafPtr(gPictureWindow);
{ Create scrap port containing game pieces}
{}
myRect.top := 0;
myRect.bottom := 329;
myRect.left := 0;
myRect.right := 329;
gScrapPtr := PortInit(myRect, depth, 'Scrap Port');
if (gScrapPtr = nil) then
begin
ExitAppl;
end; (* if *)
SetPort(savePort);
end; (* WindowInit() *)
procedure LoadPieces;
var
i, h, s: Integer;
scrapPortRect: Rect;
savePort: GrafPtr;
gamePiecePicH: PicHandle;
begin
GetPort(savePort);
SetPort(GrafPtr(gScrapPtr));
{ Load game pieces, then draw them into the scrap port}
{}
gamePiecePicH := GetPicture(500);
if gamePiecePicH = nil then
begin
ExitAppl;
end; (* if *)
scrapPortRect := gamePiecePicH^^.picFrame;
DrawPicture(gamePiecePicH, scrapPortRect);
ReleaseResource(Handle(gamePiecePicH));
SetPort(savePort);
end; (* LoadPieces() *)
procedure ToolBoxInit;
begin
{$IFC UNDEFINED THINK_PASCAL}
InitGraf(@qd.thePort);
InitFonts;
FlushEvents(everyEvent, 0);
InitWindows;
InitMenus;
TEInit;
InitDialogs(nil);
{$ENDC}
InitCursor;
MenuBarInit;
end;
end.